package nuc.lizongze.backend.service.impl;

import nuc.lizongze.backend.feign.CommonItemFeignClient;
import nuc.lizongze.backend.service.BackendService;
import nuc.lizongze.pojo.TbItem;
import nuc.lizongze.pojo.TbItemDesc;
import nuc.lizongze.pojo.TbItemParamItem;
import nuc.lizongze.utils.IDUtils;
import nuc.lizongze.utils.PageResult;
import nuc.lizongze.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class BackendServiceImpl implements BackendService {

    @Autowired
    CommonItemFeignClient commonItemFeignClient;
    @Override
    public Result selectTbItemAllByPage(Integer page, Integer rows) {

        PageResult result = commonItemFeignClient.selectTbItemAllByPage(page, rows);
        if (result != null&&result.getResult()!=null&&result.getResult().size()>0){
            return Result.ok(result);
        }
        return Result.error("查无结果");
    }

    @Override
    public Result insertTbItem(TbItem tbItem, String desc, String itemParamItem) {
        /**
         * 补充TbItem表
         */
        Long id = IDUtils.genItemId();
        Date date = new Date();
        tbItem.setId(id);
        tbItem.setStatus((byte)1);
        tbItem.setCreated(date);
        tbItem.setUpdated(date);
        Integer integer = this.commonItemFeignClient.insertTbItem(tbItem);
        /**
         * 补充TbItemDesc表
         */
        TbItemDesc tbItemDesc = new TbItemDesc();
        tbItemDesc.setItemId(id);
        tbItemDesc.setItemDesc(desc);
        tbItemDesc.setCreated(date);
        tbItemDesc.setUpdated(date);
        Integer integer2 = this.commonItemFeignClient.insertItemDesc(tbItemDesc);
        /**
         * 补充TbItemParamItem
         */
        TbItemParamItem tbItemParamItem = new TbItemParamItem();
        tbItemParamItem.setItemId(id);
        tbItemParamItem.setParamData(itemParamItem);
        tbItemParamItem.setCreated(date);
        tbItemParamItem.setUpdated(date);
        Integer integer1 = this.commonItemFeignClient.insertItemParamItem(tbItemParamItem);
        return Result.ok();
    }
}
